/*
 * KKAudioPlayer.h
 *
 *  Created on: 2013-9-15
 *      Author: wanghua
 */

#ifndef KKAUDIOPLAYER_H_
#define KKAUDIOPLAYER_H_

#include "kaka_common.h"
#include "KKCallback.h"
#include "fmod.hpp"
#include "fmod_errors.h"
#include "string"
#include <map>

using namespace std;

USING_NS_CC;

class KKAudioPlayer: public CCObject {
private:
	FMOD::Sound* m_sound;
	FMOD::Channel* m_channel;
	FMOD::ChannelGroup* m_channelGroup;

CC_PROPERTY(string,m_soundPath,SoundPath)
	;CC_SYNTHESIZE(int,m_loop,Loop)
	;CC_SYNTHESIZE(bool,m_simple,Simple)
	;CC_SYNTHESIZE(bool,m_removeCallback,RemoveCallback)
	;

	KKCallback* m_endCallback;

public:

	static FMOD::System* pSystem;

public:
	KKAudioPlayer();

	virtual ~KKAudioPlayer();

	float getDuration();

	bool isPlaying();

	void load(const char* m_soundPath);

	void play(int loop = 0);

	void rewind();

	void stop();

	void pause();

	void resume();

	void destory();

	void setVolume(float volume);
	float getVolume();

	void setEndCallback(KKCallback* callback);

	void onEndCallback();

	static void initAudioSystem();
	static void updateAudioSystem();
	static void destoryAudioSystem();
};

void ERRCHECKWITHEXIT(FMOD_RESULT result);
bool ERRCHECK(FMOD_RESULT result);
#endif /* KKAUDIOPLAYER_H_ */
